{php}$namespace = ns();{/php}
<div class="box" id="{$namespace}_box"></div>
<script>
    Namespace.register("EBCMS.{$namespace}");
    $(function(){
        EBCMS.{$namespace}.queryParams = {
            page:1,
            rows:20,
            order:{
                'id':'desc',
            },
            model:'admin/tongji',
        };
        EBCMS.{$namespace}.refresh = function refresh(p){
            if (p) {
                $.each(p, function(index, val) {
                    if (typeof val == 'object') {
                        EBCMS.{$namespace}.queryParams[index] = $.extend(EBCMS.{$namespace}.queryParams[index], p[index]);
                        delete p[index];
                    };
                });
                $.extend(EBCMS.{$namespace}.queryParams, p);
            };
            EBCMS.CORE.api({
                queryParams:EBCMS.{$namespace}.queryParams,
                tpl:'{$namespace}-table',
                target:'#{$namespace}_table',
                compileAfter:function(p){
                    EBCMS.FN.renderPage({
                        namespace:'{$namespace}',
                        total:p.data.total,
                    });
                    EBCMS.FN.renderFilter({
                        namespace:'{$namespace}',
                        filter:{
                            search:{
                                field:'title|url|ip',
                                value:''
                            },
                            order:{
                                filters:{'id':'id'}
                            },
                            rows:true,
                        }
                    });
                },
            });
        };

        EBCMS.{$namespace}.changeurl = function(url){
            EBCMS.{$namespace}.queryParams.page=1;
            EBCMS.{$namespace}.queryParams.where={
                'url':['eq',url],
            };
            EBCMS.{$namespace}.refresh();
        };

        EBCMS.{$namespace}.changeip = function(ip){
            EBCMS.{$namespace}.queryParams.page=1;
            EBCMS.{$namespace}.queryParams.where={
                'ip':['eq',ip],
            };
            EBCMS.{$namespace}.refresh();
        };

        EBCMS.{$namespace}.delete = function(type){
            EBCMS.CORE.submit({
                url:'{:url('admin/tongji/delete')}',
                queryParams:{
                    type:type,
                },
                success:function(res){
                    if (res.code) {
                        EBCMS.{$namespace}.refresh();
                    }else{
                        EBCMS.MSG.alert(res.msg);
                    }
                }
            });
        };

        EBCMS.CORE.compile({
            tpl:'{$namespace}-box',
            target:'#{$namespace}_box',
            compileAfter:function(){
                EBCMS.{$namespace}.refresh();
            }
        });
    });
</script>

<script id="{$namespace}-box" type="text/html">
    <div class="header">
        <div class="header-title" onclick="EBCMS.CORE.changemain('{:url('admin/tongji/index')}');">访问管理</div>
        <div class="header-title" onclick="EBCMS.CORE.changemain('{:url('admin/tongji/index?type=2')}');">页面统计</div>
        <div id="{$namespace}_filter" class="footer-page"></div>
        <div class="btn-group">
            <button class="btn btn-primary" onclick="EBCMS.CORE.getconfig('{:eb_encrypt('name|tongji')}');">设置</button>
            <button class="btn btn-primary" onclick="delete EBCMS.{$namespace}.queryParams.where;EBCMS.{$namespace}.refresh();">全部</button>
        </div>
    </div>
    <div class="body">
        <div id="{$namespace}_table" class="box"></div>
    </div>
    <div class="footer">
        <div id="{$namespace}_page" class="footer-page"></div>
        <div class="btn-group dropup">
          <button type="button" class="btn btn-primary">删除</button>
          <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <span class="caret"></span>
            <span class="sr-only">Toggle Dropdown</span>
          </button>
          <ul class="dropdown-menu">
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('3');">三天之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('7');">一周之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('14');">两周之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('21');">三周之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('28');">四周之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('60');">两个月之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('90');">三个月之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('120');">四个月之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('150');">五个月之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('180');">六个月之前</a></li>
            <li><a href="###" onclick="EBCMS.{$namespace}.delete('365');">一年之前</a></li>
          </ul>
        </div>
    </div>
</script>

<script id="{$namespace}-table" type="text/html">
    <table class="table table-bordered table-hover table-ebcms">
        <tbody>
            <tr>
                <th style="width:70px;">id</th>
                <th>链接</th>
                <th>ip</th>
                <th>时间</th>
                <th>标题</th>
            </tr>
            [[include '{$namespace}-table-item' data]]
        </tbody>
    </table>
</script>

<script id="{$namespace}-table-item" type="text/html">
    [[each rows as v n]]
        <tr>
            <td>[[v.id]]</td>
            <td><button class="btn btn-xs" onclick="EBCMS.{$namespace}.changeurl('[[v.url]]');">[[v.url]]</button></td>
            <td><button class="btn btn-xs" onclick="EBCMS.{$namespace}.changeip('[[v.ip]]');">[[v.ip]]</button></td>
            <td>[[v.create_time]]</td>
            <td>[[v.title]]</td>
        </tr>
    [[/each]]
</script>